import {
    GetTagListWithPage,
    BatchDelTag,
    DelTag,
    AddTag,
    FindTag,
    UpdateTag,
    ExportTag
} from '@/services/customer/tag';
import {catchException} from '@/utils/utils';
export default {
    namespace: 'customertag',

    state: {
        PageData: {},
        TagModel: {},
    },
    effects: {
        *TagList({ param, callback }, { call, put }) {
            const data = yield call(GetTagListWithPage, param);
            yield catchException(function* (){
                yield put({
                    type: 'getTagList',
                    pageData: data.Data,
                });
                callback && callback(data.Data);        
            })            
        },
        *BatchDelTag({ param, callback }, { call, put }) {
            const data = yield call(BatchDelTag, param);           
            yield catchException(function* (){
                callback && callback(data.Data);        
            }) 
        },
        *DelTag({ param, callback }, { call, put }) {
            const data = yield call(DelTag, param);
            yield catchException(function* (){
                callback && callback(data.Data);        
            })
        },
        *AddTag({ param, callback }, { call, put }) {
            const data = yield call(AddTag, param);
            yield catchException(function* (){
                callback && callback(data);        
            })
        },
        *UpdateTag({ param, callback }, { call, put }) {
            const data = yield call(UpdateTag, param);
            yield catchException(function* (){
                callback && callback(data);        
            })
        },
        *ExportTag({ param, callback }, { call, put }) {
            const data = yield call(ExportTag, param);
            yield catchException(function* (){
                if (data.Code == 0) {
                    callback && callback.success && callback.success(data.Data);
                } else {
                    callback && callback.error && callback.error(data.Data);
                }        
            })            
        },
        *FindTag({ param, callback }, { call, put }) {
            const data = yield call(FindTag, param);
            yield catchException(function* (){
                yield put({
                    type: 'getTag',
                    tag: data.Data,
                });
                callback && callback(data.Data);       
            })             
        }

    },
    reducers: {
        getTagList(state, { pageData }) {
            return { ...state, PageData: pageData };
        },
        getTag(state, { tag }) {
            return { ...state, TagModel: tag };
        }
    }
}
